import 'package:dmz/base/pageWidget/base_stateful_widget.dart';
import 'package:dmz/base/widget/defult_widget.dart';
import 'package:dmz/business/login/widgets/login_widgets.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';

class EMILoding {
  static hitLoding(String text,
      {double? durationSeconds, bool isScuess = false}) {
    Widget _errorWidget(String text) {
      return Container(
        constraints: BoxConstraints(
          minWidth: 150.sp, // 最小宽度
        ),
        padding: EdgeInsets.only(
            left: 20.sp, right: 20.sp, top: 26.sp, bottom: 26.sp),
        decoration: BoxDecoration(
          color: Colors.white,
          borderRadius: BorderRadius.circular(4.sp),
        ),
        child: Row(mainAxisSize: MainAxisSize.min, children: [
          Image.asset(
              isScuess
                  ? 'assets/images/login/success_icon.png'
                  : 'assets/images/login/input_hit.png',
              width: 48.sp,
              height: 48.sp),
          SizedBox(width: 20.sp),
          Container(
              constraints: BoxConstraints(maxWidth: 450.sp),
              child:
                  DefaultText(text, 28.sp, textColor: const Color(0xA6000000))
                      .marginOnly(right: 28.sp))
        ]),
      );
    }

    EasyLoading.instance.maskType = EasyLoadingMaskType.none;
    EasyLoading.instance.maskColor = Colors.transparent;
    EasyLoading.instance.loadingStyle = EasyLoadingStyle.custom;
    EasyLoading.instance.backgroundColor = Colors.white;
    EasyLoading.instance.indicatorColor = Colors.white;
    EasyLoading.instance.textColor = Colors.transparent;
    EasyLoading.instance.progressColor = Colors.transparent;
    EasyLoading.instance.maskType = EasyLoadingMaskType.none;
    EasyLoading.instance.contentPadding = EdgeInsets.zero;
    EasyLoading.instance.toastPosition = EasyLoadingToastPosition.bottom;
    EasyLoading.instance.maskType = EasyLoadingMaskType.none;
    EasyLoading.show(indicator: _errorWidget(text), dismissOnTap: true);
    Future.delayed(
        Duration(milliseconds: ((durationSeconds ?? 1.5) * 1000).toInt()), () {
      EasyLoading.dismiss();
    });
  }

  static didLoding() {
    EasyLoading.show();
  }

  ///隐私弹框
  /// type 窗口点击 0 用户协议 1 隐私 2 不同意 3 同意
  static showInteractivePopUpBox(
      BuildContext contexted, Function(int type) click) {
    _clickBtn(String title, int type) {
      return Expanded(
          child: GestureDetector(
              onTap: () {
                click(type);
                Navigator.of(contexted).pop();
              },
              child: Container(
                  height: 97.sp,
                  alignment: Alignment.center,
                  color: Colors.transparent,
                  child: DefaultText(title, 33.sp,
                      textColor:
                          type == 1 ? Color(0xFF23C565) : Color(0xFF000000)))));
    }

    showDialog<bool>(
        barrierDismissible: false,
        context: contexted,
        builder: (context) {
          return Container(
              alignment: Alignment.center,
              child: Container(
                  decoration: BoxDecoration(
                    color: Colors.white,
                    borderRadius: BorderRadius.circular(26.sp),
                  ),
                  margin: EdgeInsets.only(left: 40.sp, right: 40.sp),
                  child: Column(mainAxisSize: MainAxisSize.min, children: [
                    DefaultText('用户协议与隐私政策', 40.sp,
                            textColor: Colors.black,
                            fontWeight: FontWeight.w600)
                        .marginOnly(top: 52.sp, bottom: 32.sp),
                    Container(
                        alignment: Alignment.centerLeft,
                        padding: EdgeInsets.only(left: 32.sp, right: 32.sp),
                        child: LoginWidgets.getRichTexts(
                            '我们依据最新法律规定更新了《用户协议》及《隐私政策》，请查阅。保护您的隐私对我们至关重要，我们将遵守适用法律规定的要求对您的信息予以充分保护，并使您能够更好地行使个人权利。根据您的选择，本软件在使用过程中可能需要申请联网、定位、文件储存等权限。请您务必审慎、仔细阅读《用户协议》和《隐私政策》相关条款，特别是免除或者限制责任的条款、法律适用和争议解决条款，您可以点击下述链接完整阅读《用户协议》、《隐私政策》文本。您需阅读并同意相关政策条款方可使用本软件[特别提醒】 当您点击“同意”即表示您已充分阅读、理解并接受《用户协议》及《隐私政策》您需阅读并同意相关政策条款方可使用本软件',
                            '《用户协议》',
                            '《隐私政策》',
                            '您需阅读并同意相关政策条款方可使用本软件',
                            (type) => click(type),
                            defulColor: Colors.black,
                            fontSize: 36.sp)),
                    Container(height: 2.sp, color: Color(0x4D000000))
                        .marginOnly(top: 42.sp),
                    Row(children: [
                      _clickBtn('不同意', 2),
                      Container(
                          height: 97.sp, width: 2.sp, color: Color(0x4D000000)),
                      _clickBtn('同意并继续', 3),
                    ])
                  ])));
        });
  }

  static showCustomizeDialog(BuildContext contexted, Widget child) {
    showDialog<bool>(
        barrierDismissible: false,
        context: contexted,
        builder: (context) {
          return child;
        });
  }

  static showBottomHitWindow(title, content, Function(bool) callBack,
      {Function()? close, bool isDismissible = false, bool showBack = false}) {
    showBottomWindow(hitBottomWidget(title, content, callBack),
        close: close, isDismissible: isDismissible, showBack: showBack);
  }

  static showBottomWindow(Widget child,
      {Function()? close, bool isDismissible = false, bool showBack = false}) {
    Get.bottomSheet(child,
            isScrollControlled: true,
            barrierColor: showBack ? null : Colors.transparent,
            isDismissible: isDismissible)
        .then((value) {
      debugPrint('窗口关闭 ---- 0022 $close');
      close?.call();
    });
  }

  static Widget hitBottomWidget(title, content, Function(bool) callBack) {
    return Container(
        decoration: BoxDecoration(
            color: Colors.white,
            borderRadius: BorderRadius.only(
                topRight: Radius.circular(60.sp),
                topLeft: Radius.circular(60.sp))),
        child: Column(mainAxisSize: MainAxisSize.min, children: [
          DefaultText('$title', 48.sp, textColor: Colors.black)
              .marginOnly(top: 122.sp),
          DefaultText('$content', 32.sp, textColor: Colors.black)
              .marginOnly(bottom: 112.sp, top: 20.sp)
              .marginOnly(left: 32.sp, right: 32.sp),
          Container(
              padding: EdgeInsets.only(top: 2.sp),
              height: 120.sp,
              color: const Color(0xFFD8D8D8),
              child: Row(children: [
                Expanded(
                    child: Container(
                            alignment: Alignment.center,
                            color: Colors.white,
                            child: DefaultText('取消', 32.sp,
                                textColor: const Color(0xFF000000)))
                        .addGestureDetector(() => callBack(false))),
                SizedBox(width: 2.sp),
                Expanded(
                    child: Container(
                            alignment: Alignment.center,
                            color: Colors.white,
                            child: DefaultText('确认', 32.sp,
                                textColor: const Color(0xFF23C565)))
                        .addGestureDetector(() => callBack(true)))
              ]))
        ]));
  }
}
